<?php 
	$customerid=Mage::getSingleton('customer/session')->getCustomerId();
	$isPartner= Mage::getModel('marketplaceprofile/marketplaceprofile')->isPartner($customerid);
	if($isPartner==1){?>
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/global.css'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	if (typeof jQuery == 'undefined'){
		document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
	}
</script> 
<script src="<?php echo $this->getSkinUrl('Customerpartner/js/nicEdit-latest.js'); ?>" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
  bkLib.onDomLoaded(function(){
	new nicEditor({fullPanel : true}).panelInstance('description');
	new nicEditor({fullPanel : true}).panelInstance('short_description');     
  });
  //]]>
</script>
<script src="<?php echo Mage::getBaseUrl('js').'calendar/calendar.js';?>" type="text/javascript"></script>
<script src="<?php echo Mage::getBaseUrl('js').'calendar/calendar-setup.js';?>" type="text/javascript"></script>
<?php
	$url= $_SERVER['REQUEST_URI'];
	$urlarr=explode('/id/',$url);
	echo $this->getMessagesBlock()->getGroupedHtml();
	$product = $this->getProduct();
	$productcity = Mage::getModel('catalog/product');
	$loadpro= $productcity->load($urlarr[1]);
	$cat=$loadpro->getCategoryIds();
	$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($urlarr[1])->getQty();				
	$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter();
	$allcatid = array();
	$k=0;
	foreach($categories as $c){
		$allcatid[$k] = $c->getId();
		$k++;
	}
	$finalcat=array_shift($allcatid);	
?>
	<div class="prdouctbackground">		
		<form action="<?php echo $this->getUrl('customer/products/editapprovedsimple') ?>" enctype="multipart/form-data" method="post" id="form-customer-product-editPost">
			<input type="hidden" name="productid" value="<?php echo $urlarr[1]; ?>" />
			<fieldset class="group-select" >
				<div id="customerpartner-products">
					<h4 class="textcolor"><?php echo Mage::helper('marketplacepartner')->__('Edit Simple Magento Product') ?></h4>
					<table class="tablepostion" >
					<thead><tr><th colspan="2" class="headingbg"><?php echo Mage::helper('marketplacepartner')->__('Product Information') ?></th></tr></thead>
					<tbody id="tbodying">
						<tr>
							<td class="tdpadfirst">
								<label for="category" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Category :') ?></label>
								<span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<select id="category" class="myinput-text required-entry widthinput" name="category"   >
								<?php foreach($allcatid as $keycat){ 
											if($keycat==$cat[0]){?>
												<option selected="selected" value="<?php echo $keycat;?>"><?php echo Mage::getModel("catalog/category")->load($keycat)->getName() ?></option>
											<?php }else {?>
												<option value="<?php echo $keycat;?>"><?php echo Mage::getModel("catalog/category")->load($keycat)->getName() ?></option>
											<?php }?>
								<?php } ?>
								</select>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="name" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Name')?> :</label> 
								<span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="name" class="required-entry widthinput" name="name" id="name" value="<?php echo $loadpro->getName(); ?>" />
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="description" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Description') ?> :</label>
								<span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<textarea name="description" class="required-entry " id="description" rows="5" cols="75" ><?php echo $loadpro->getDescription(); ?></textarea>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="short_description" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Short description') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<textarea name="short_description" id="short_description" rows="5" cols="75" class="required-entry input-text"><?php echo $loadpro->getShortDescription();?></textarea>
							</td>
						</tr>
						<tr> 
							<td class="tdpadfirst">
								<label for="sku" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('SKU') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input name="sku" id="sku" class=" required-entry widthinput" value="<?php  echo $loadpro->getsku(); ?>"/> 
								<div id="skuavail" ><img src="<?php echo $this->getSkinUrl('customerurlpic/available.png'); ?>"/><span><?php echo Mage::helper('marketplacepartner')->__('SKU Available') ?></span></div>
								<div id="skunotavail" ><img src="<?php echo $this->getSkinUrl('customerurlpic/x-mark.jpg'); ?>"/><span><?php echo Mage::helper('marketplacepartner')->__('SKU Already Exist') ?></span></div>
							</td>
						</tr>				
						<tr>
							<td class="tdpadfirst">
								<label for="price" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Price') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="price" class=" required-entry widthinput" name="price" id="price" value="<?php  echo $loadpro->getPrice(); ?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="stock" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Stock') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="stock" class=" required-entry widthinput" name="stock" id="stock" value="<?php echo $qtyStock; ?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="weight" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Weight') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="weight" class=" required-entry widthinput" name="weight" id="weight"  value="<?php echo $loadpro->getWeight();?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="file" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Image') ?></label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class='tdpadsec'>
									<input type='file' name='images'/>
									<br>
									<a style="margin-top:10px;" href='#' onClick='showOtherImage(); return false;'><?php echo Mage::helper('marketplacepartner')->__("Add Other Image");?></a><br/>
									<div id='otherimages'></div>
									<div class="image_set">
									<?php $_product = Mage::getModel('catalog/product')->load($loadpro->getId())->getMediaGalleryImages();
									?>
									
									<?php if($_product) {  ?>
										<?php $i=0;
												  foreach($_product as $_image) { 
												  $i++; 
												  ?>
												  <div style="padding:5px; float:left;width:50px;height:55px;">
													  <img id="<?php echo $_image->getFile(); ?>" pid="<?php echo $loadpro->getId(); ?>" src="<?=$this->helper('catalog/image')->init($_product, 'thumbnail',$_image->getFile())->resize(200, 130); ?>" width="50" height="50" alt="<?=$this->htmlEscape($_image->getLabel());?>" title="<?=$this->htmlEscape($_image->getLabel()); ?>" />
													  <span style="display:none;position:relative;top:-37px;left:6px;"><?php echo Mage::helper('marketplacepartner')->__('Delete') ?></span>
												  </div>
										
									   <?php  } ?>
									<?php  } ?>
									</div>
									
								</td>
						</tr> 
						<!--shipping info-->
						<?php //echo $this->getLayout()->createBlock('core/template')->setTemplate('customoption/editcustomoption.phtml')->toHtml(); ?>
					</tbody>	
				</table>
			</div>
			<div class="button-set buttonarea">
				<p class="headingbackindex">
					<a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo Mage::helper('marketplacepartner')->__('Back') ?></a>
				</p>
				<center>
					<button type="submit" class="form-button btn"><span><?php echo Mage::helper('marketplacepartner')->__('Save') ?></span></button>
				</center>
			</div>
		</fieldset>
	</form>
</div>
<!--
end new product
-->

<script> 
var $wk_jq=jQuery.noConflict();
(function($wk_jq){
	$wk_jq(function(){
		$wk_jq('input#sku').change(function(){
			var len=$wk_jq('input#sku').val();
			var len2=len.length;
			if(len2==0){
				alert("<?php echo Mage::helper('marketplacepartner')->__('SKU can\'t be left empty') ?>");
				$wk_jq('div#skuavail').css('display','none');
				$wk_jq('div#skunotavail').css('display','none');
			}
			else{
				$wk_jq.ajax({
					url: "<?php echo Mage::getUrl('customer/products/verifysku');?>",
					type: "POST",
					data: {sku:$wk_jq('input#sku').val()},
					dataType: 'html',
					success:function($data){
						$data=JSON.parse($data);
						if($data.avl==1){
							$wk_jq('div#skuavail').css('display','block');
							$wk_jq('div#skunotavail').css('display','none');
						}
						else{
							$wk_jq('div#skunotavail').css('display','block');
							$wk_jq('div#skuavail').css('display','none');
							$wk_jq("input#sku").attr('value','');
						}
					}
				});
			}
		});
	
		$wk_jq('.image_set div').click(function(event){
			var dicisionapp=confirm('Sure Want To Delete Image');
			if(dicisionapp==true){
				var imag = $wk_jq(this).find('img').attr('id');
				$wk_jq.ajax({
					url: "<?php echo $this->getUrl('marketplacepartner/partnerproducts/deleteimage');?>",
					type: "POST",
					data: {file:$wk_jq(this).find('img').attr('id'),pid:$wk_jq(this).find('img').attr('pid')},
					dataType: 'html',
					success:function(content){
						$wk_jq(this).remove();
					}
				});
				$wk_jq(this).remove();
			}		
		});
		$wk_jq('.image_set img').mouseover(function(event){
			$wk_jq(event.target).parent('div').find('span').css({display:'block'});
			$wk_jq(event.target).parent('div').find('img').css('opacity','0.4');
		});
		$wk_jq('.image_set img').mouseout(function(event){
			$wk_jq(event.target).parent('div').find('span').css({display:'none'});
			$wk_jq(event.target).parent('div').find('img').css('opacity','1');
		});

		$wk_jq('.image_set span').mouseover(function(event){
			$wk_jq(event.target).parent('div').find('span').css({display:'block'});
			$wk_jq(event.target).parent('div').find('img').css('opacity','0.4');
		});
		$wk_jq('.image_set span').mouseout(function(event){
			$wk_jq(event.target).parent('div').find('span').css({display:'none'});
			$wk_jq(event.target).parent('div').find('img').css('opacity','1');
		});
	})
})($wk_jq);
	

</script>	
<script type="text/javascript">
	var newCustomerProductForm = new VarienForm('form-customer-product-editPost', true);
	var i=2;
	function showOtherImage() {
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id","childDiv"+i);
		newdiv.innerHTML = "<input type='file' name='images"+i+"' /><a href=\"javascript:;\" onclick=\"removeEvent('childDiv"+i+"')\"><?php echo Mage::helper('marketplacepartner')->__('Remove') ?></a>";
		var ni = document.getElementById('otherimages');
		ni.appendChild(newdiv);
		i++;
	}

	function removeEvent(divNum){
		var d = document.getElementById('otherimages');
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
		i--;
	}
</script>
<?php }else{
	echo Mage::helper('marketplacepartner')->__("<h2 style='color:#ff0000;font-weight:600'>FOR BECOME SELLER CONTACT TO ADMIN..</h2>");
}?>